package com.campus.web.controller;


import com.aliyuncs.ecs.model.v20140526.CopyImageRequest;
import com.campus.app.service.AnnunciatesService;
import com.campus.commons.entity.Annunciate;
import com.campus.commons.entity.AnnunciateType;
import com.campus.commons.utils.MyPage;
import com.campus.commons.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;

/**
 * <p>
 * 公告 前端控制器
 * </p>
 *
 * @author Rin
 * @since 2020-12-24
 */
@RestController
@RequestMapping("/annunciate")
public class AnnunciateController {


    @Autowired
    private AnnunciatesService annunciatesService;

    @GetMapping("/")
    public ModelAndView toIndex(ModelMap modelMap) {
        modelMap.addAttribute("types", AnnunciateType.annunciateTypeMap.values());
        return new ModelAndView("learn/annuciate/index",modelMap);
    }


    @PostMapping("/all")
    /**
     * 是否过滤请求； filter过滤
     */
    @ApiOperation(value = "获取公告；需要传入分页参数和是否过滤禁用的公告")
    public Result getAllAnnunciates(Integer page,Integer limit,boolean filter) {
        return annunciatesService.getAllAnnunciates(new MyPage(1, 10),filter);
    }
    @ApiOperation(value = "获取公告信息；必要参数page 页 ， limit 返回的数量；过滤条件: annTypeId： 公告类型Id； ")
    @PostMapping("/search")
    public Result getAnnunciates(MyPage<Annunciate> myPage,Annunciate annunciate) {
        myPage.setData(annunciate);
        return annunciatesService.getAnnunciates(myPage);
    }


    @PostMapping("/add")
    public Result addAnnunciates(Annunciate annunciate) {
        return annunciatesService.addAnnunciate(annunciate);
    }
    @PostMapping("/del")
    public Result deleteAnnunciate(int id) {
        return annunciatesService.deleteAnnunciateById(id);
    }

    @PostMapping("/update")
    public Result updateAnnunciate(@Valid Annunciate annunciate) {
        return annunciatesService.upAnnunciate(annunciate);
    }
    @PostMapping("/stick")
    public Result stickAnnunciate(int id) {
        return annunciatesService.stickAnnunciate(id);
    }

}

